package org.jeecg.modules.lottery.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.lottery.entity.Lottery;
import org.jeecg.modules.purchase.entity.PurchasePlan;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository//purchase_id
public interface LotteryMapper extends BaseMapper<Lottery> {

    @Select("SELECT * FROM proc_purchase_plan WHERE category = #{category}")
     List<PurchasePlan> getEligiblePurchasePlan(String category);


    @Select("SELECT supplier_id FROM proc_lottery WHERE purchase_id = #{purchaseId} AND lottery_status != '2'")
    List<String> getSelectedSupplierIds(@Param("purchaseId") String purchaseId);

    @Select("SELECT COUNT(*) FROM proc_lottery WHERE purchase_id = #{purchaseId} AND lottery_status = '2'")
    int getAbandonedCount(@Param("purchaseId") String purchaseId);

    @Select("SELECT COUNT(*) FROM proc_lottery WHERE purchase_id = #{purchaseId} AND lottery_round = #{round}")
    int getLotteryCountByRound(@Param("purchaseId") String purchaseId, @Param("round") Integer round);



}
